package xyz.xtt.exchange.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import xyz.xtt.exchange.entity.TblMerchantInfo;
import xyz.xtt.exchange.mapper.TblMerchantInfoMapper;
import xyz.xtt.exchange.service.ITblMerchantInfoService;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author dale
 * @since 2025-03-18
 */
@Service
public class TblMerchantInfoServiceImpl extends ServiceImpl<TblMerchantInfoMapper, TblMerchantInfo> implements ITblMerchantInfoService {

    @Override
    public Boolean judgeMerchantPer(String uid) {
        TblMerchantInfo tblMerchantInfo = getMchShop(Long.valueOf(uid));
        return tblMerchantInfo != null && tblMerchantInfo.getMerchantStatus() == 1;
    }

    @Override
    public TblMerchantInfo getMchShop(Long uid) {
        LambdaQueryChainWrapper<TblMerchantInfo> query = new LambdaQueryChainWrapper<>(baseMapper);
        query.eq(TblMerchantInfo::getAppUserId, uid)
                .orderByDesc(TblMerchantInfo::getCreateTime)
                .last("limit 1");
        return baseMapper.selectOne(query.getWrapper());
    }


}
